/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;

/**
 *
 * @author serga
 */
@Entity
@Table(name="comments" , catalog="", schema="")
@NamedQueries({
    @NamedQuery(name="Comments.getProductsComments", query = "SELECT c FROM comments c WHERE o.id = :id_product" ),
    @NamedQuery(name="Comments.getQuestionsComments", query = "SELECT c FROM comments c WHERE o.id_user = :id_question")
})
public class Comments extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Temporal(javax.persistence.TemporalType.DATE)
    @Column(name="date_published", nullable=false)
    private Date date_published;
    @Column(name="text", nullable=false)
    private String text;
    

    @ManyToOne
    @JoinColumn(name="id_user", referencedColumnName="id")
    private Comments comments;
    
   
    
    private Users author; 
           
    /*private  String text;*/

    public Comments() {
    }
    
      
    public Comments (Long id) {
        this.id = id;
    } 
    
    public Comments (Users author,Date date_published,String text) {
        this.author = author;
        this.date_published = date_published;
        this.text = text;
    }
    
    
    public Date getDatetime() {
        return date_published;
    }

    public void setDateTime(Date date_published) {
        this.date_published = date_published;
    }

    

    
    
    public Users getAuthor() {
        return author;
    }

    public void setAuthor(Users author) {
        this.author = author;
    }
    
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
    
    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Comments)) {
            return false;
        }
        Comments other = (Comments) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "models.Comments[ id=" + id + " ]";
    }
    
}